package com.Servlet;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jdbc.Jdbc;

/**
 * Servlet implementation class searchcontractbyperson
 */
@WebServlet("/searchcontractbyperson")
public class searchcontractbyperson extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public searchcontractbyperson() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


		request.setCharacterEncoding("utf-8");
		ResultSet rs=null;
		String chinesename= request.getParameter("chinesename");
		String username = (String) request.getSession().getAttribute("username");
		String role = (String) request.getSession().getAttribute("role");
		String find=null;
		if (role.equals("管理员")) {
			find = "select*from contract where chinesename like'"+chinesename+"%'";
		} else {
			find = "select*from contract where chinesename like '"+chinesename+"%' and username="+username;
		}
		System.out.println(find);
		Jdbc j3 = new Jdbc();
		try {
			j3.Jdbc_Q2(find);
			rs = j3.rs;
			request.setAttribute("resultset", rs);
			request.getRequestDispatcher("searchcontractbyname.jsp").forward(request, response);
		} catch (ClassNotFoundException | SQLException e) {
			//结果是查无此人的时候从这个页面跳出去
			
		}
		finally {
			
		}
	
	
	}

}
